#pragma once

#include <map>
#include <shellapi.h>
#include "HttpSocket.h"
#include "../CommonFounction.h"
#include <string>
#include <vector>
#include "Download_i.h"

#define  BUFFER_SIZE  1024 * 8


class CDownload : public IDownload
{
public:
	CDownload();
	CDownload(const std::string& rootIP,const std::string& versionIP,const int port=80);
	~CDownload();

	void InitializeDownload(const std::string& rootIP,const std::string& versionIP,const int port=80);

	//IDownload
	virtual void setEventHandler(IDownloadEvent* pEventHandler) ;
	virtual bool DownloadHTTP(const string& ip,const string& srcFile,const string& dstFile,bool isForceUpdate,bool isShow,long from=-1);
	//virtual	size_t ComputeFileTotalSize(FileData*  pstFiles, size_t nFilesCount);
	//virtual size_t ComputeXmlTotalSize();
protected:
	bool CreateDirectoryByFilePath(const string& file);
	bool FileIsExist(LPCSTR szFileFullPathName);
	void DeleteAllEXE();

protected:
	const static int TIMEOUT=30000;

	std::string m_RootIP,m_VersionDomain;
	int m_Port;
	IDownloadEvent* m_eventListener;
	long m_lCurDownloadByte;
	
};


